<?php  
class ControllerNewsNews extends Controller {
	public function index() {
	//	$this->language->load('common/footer');
    $this->document->title = 'NYHEDER';
    
		$this->load->model('news/news');
        $limit = 1024;
        $page  = isset($this->request->get['page']) ? $this->request->get['page'] : 1;  
        
        $content_total = $this->model_news_news->getTotalArticles();            
        $contents = $this->model_news_news->getAllarticle($page, $limit);

        $this->data['contents'] = array();
        if($contents){	
            $this->load->model('tool/image');
            $this->load->model('tool/seo_url');
            
            foreach($contents as $item){                
                $title = $item['name'];               
                
                $image = $item['image'] ? $this->model_tool_image->resize($item['image'], 122, 75) : null; 
                
                $desc_info = html_entity_decode($item['description']);        
                if(stripos($desc_info, '<hr />')){
                    $description = explode('<hr />', $desc_info);              
                    $description = strip_tags($description[0], '<a>') . '...';
                }
                else{        
                    $description = (strlen($desc_info) > 200) ? (mb_substr(strip_tags($desc_info), 0, 350) . ' ...') : html_entity_decode($item['description']);    
                }
                                
                $this->data['contents'][] = array(
                    'title'         => $item['name'],                  
                    'image'         => $image,
                    'text'          => $description,
                    'readmore'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=news/list&content_id=' . $item['content_id']),                    
                );           
            }            
            
            $pagination = new Pagination();
			$pagination->total = $content_total;
			$pagination->page = $page;
			$pagination->limit = $limit; 
			$pagination->text = $this->language->get('text_pagination');
			$pagination->url = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=news/news&page={page}');			
			$this->data['pagination'] = $pagination->renderFrontend();  
        }
        
        $this->children = array(
			'common/column_right',
			'common/column_left',
			'common/footer',
			'common/header'
		);
        
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/news/news.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/news/news.tpl';
		} else {
			$this->template = 'default/template/news/news.tpl';
		}
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}
}
?>